//
//  QCAlertPopViewController.swift
//  FMate
//
//  Created by xinglian on 2022/1/11.
//

import UIKit
import TCCKit
typealias enterBtnBlock = ()->Void

enum alertType : Int
{
    case normal = 1
    case olnyEnter = 2
}
class QCAlertPopViewController: CCAlertViewController {
    @IBOutlet weak var alertView: UIView!
    @IBOutlet weak private var msg: UILabel!
    @IBOutlet weak var leftBtn: UIButton!
    @IBOutlet weak var rightBtn: UIButton!
    @IBOutlet var rightBtnLeft: NSLayoutConstraint!
    var leftBtnBlock : enterBtnBlock?
    var rightBtnBlock : enterBtnBlock?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    var type : alertType = .normal
    {
        didSet
        {
            switch type{
            case .normal:
                leftBtn.isHidden = false
                rightBtn.isHidden = false
            case .olnyEnter:
                leftBtn.isHidden = true
                rightBtn.isHidden = false
                rightBtnLeft.constant = -alertView.bounds.width / 2.0
            }
        }
    }
    
    @objc func show(_ title : String)
    {
        self.msg.text = LS(title)
        self.currentVC().present(self, animated:false, completion:nil)
    }
    @objc func show(_ title : String, _ leftTitle:String, _ rightTitle:String)
    {
        if  self.currentVC().className == "QCAlertPopViewController"{return}
        self.msg!.text = LS(title)
        self.leftBtn.setTitle(LS(leftTitle), for: .normal)
        self.rightBtn.setTitle(LS(rightTitle), for: .normal)
        self.currentVC().present(self, animated:false, completion:nil)
    }
    
    func show(_ type:alertType = .normal,_ title : String)
    {
        self.msg.text = LS(title)
        self.type = type
        self.currentVC().present(self, animated:false, completion:nil)
    }
    @IBAction func methodForCancel(_ sender: UIButton)
    {
        self.dismiss(animated:false, completion: nil)
        self.leftBtnBlock?()
    }
    
    @IBAction func methodForEnter(_ sender: UIButton)
    {
        self.dismiss(animated:false, completion:{
            self.rightBtnBlock?()
        })
    }
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    }
}
